package logic

import (
	"context"
	"gorm.io/gorm"
	"home-mgr/homerpc/homerpc"
	"home-mgr/homerpc/internal/svc"
	"home-mgr/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type PreUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPreUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PreUpdateLogic {
	return &PreUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PreUpdateLogic) PreUpdate(in *homerpc.PreUpdateRequest) (*homerpc.PreUpdateResponse, error) {
	// todo: add your logic here and delete this line

	pre := model.Pre{
		Model: gorm.Model{
			ID: uint(in.PreId),
		},
		UserId:  int(in.UserId),
		HouseId: int(in.HouseId),
		Status:  "已取消",
	}
	model.DB.Debug().Updates(&pre)
	return &homerpc.PreUpdateResponse{
		PreId: int64(pre.ID),
	}, nil
}
